package com.platform.corejwt.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 测试
 * @author rainly
 */
@Api(value = "测试类")
@RestController
public class TestController {

    @Resource
    private RedisTemplate redisTemplate;

    @ApiOperation(value = "测试",notes = "测试用例", httpMethod = "GET")
    @RequestMapping(value = "/test",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
    public String test(@ApiParam(value = "字符串",required = true) @RequestParam String s){
        return "success";
    }
    @ApiOperation(value = "往redis插入数据")
    @RequestMapping(value = "setValue",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
    public String setValue(@RequestParam String value){
        redisTemplate.opsForValue().set("test", value);
        return value;
    }

    @RequestMapping(value = "getValue",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
    public String getValue(){
        return redisTemplate.opsForValue().get("test").toString();
    }

    @RequestMapping(value = "/getAddr", method= RequestMethod.GET)
    public String getAddress() {
        redisTemplate.opsForValue().set("001", "河北省");
        Object o = redisTemplate.opsForValue().get("001");
        return o.toString();
    }

}